package com.yun.algorithmproblem.leetcode;

public class Leetcode680 {


    public boolean validPalindrome(String s) {
        char[] chars = s.toCharArray();
        int p = 0, q = chars.length - 1;
        while (p < q) {
            if (chars[p] != chars[q]) {
                return palindrome(chars, p + 1, q) || palindrome(chars, p, q - 1);
            }
            p++;
            q--;
        }
        return true;
    }

    private boolean palindrome(char[] chars, int p, int q) {
        while (p < q) {
            if (chars[p] != chars[q]) {
                return false;
            }
            p++;
            q--;
        }
        return true;
    }
}
